layui.use(['form', 'layer', 'upload', 'laydate', 'okAddlink'], function () {
	var form = layui.form;
	var upload = layui.upload;
	var $ = layui.jquery;
	var laydate = layui.laydate;
	var $form = $('form');
	var okAddlink = layui.okAddlink.init({
		province: 'select[name=province]',
		city: 'select[name=city]',
		area: 'select[name=area]',
	});
	okLoading.close();
	laydate.render({
		elem: '#uDate', //指定元素
		max: "2019-1-1",
		value: '2017-09-10',
	});

	okAddlink.render();//渲染三级联动省市区
	/*


	 */
	//监听提交(修改个人信息) 跳登录页面
	form.on('submit(changeUser)', function(data){
		var index = layer.msg('提交中，请稍候', {icon: 16, time: 3000, shade: 0.8},function () {
			var url = "/perUsers/updateBasicInformation";
			var formData = new FormData(document.getElementById("myfrom1"));
			$.ajax({
				url:url,
				data:formData,
				processData:false,
				contentType:false,
				dataType:'json',
				type:'POST',
				success:function(obj){
					console.info(obj);
					if(obj.status==20){
						layer.msg(obj.message,{time:1500,icon:1},function () {
							$.post('/admin/exitLogon',null,function (obj) {
								if(obj.status==20){
									console.info(obj.message)
									top.location.href="/ok-admin/pages/login.html";
								}
							},"json");
						});
					}else if(obj.status==6){
						layer.msg(obj.message,{time:1500,icon:2});
					}else {
						layer.msg(obj.message,{time:1500,icon:2});
					}
				},
				error:function(){

				}
			})
			return false;
		});
		return false; //阻止表单跳转。，如果需要表单跳转去掉这段即可。
	});

	/**
	 * 取到登入以后的个人信息
	 * @type {string}
	 */
	var url = "/admin/userMessage";
	$.ajax({
		url:url,
		data:null,
		dataType:'json',
		type:'POST',
		success:function(obj){
			console.info(obj);
			if(obj.status == 20){
				form.val('myfrom',obj.data);
				//设置图片
				if(obj.data.userImg){
					$("#prePic").prop("src","/"+obj.data.userImg);
				}else{
					$("#prePic").prop("src","/img/no-img_mid_.jpg");
				}

			}else{
				window.location.href = "pages/login.html";
			}
		},
		error:function(){

		}
	});


});























